package controllerCon;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;
import javax.swing.JTable;

import pnlBeheer.PnlGDBeheer;
import tblModelDrank.TMADrank;
import tblModelDrank.TMDrank;
import tblModelDrank.TMRDrank;
import tblModelGerecht.TMAGerecht;
import tblModelGerecht.TMGerecht;
import tblModelGerecht.TMRGerecht;

public class ConCbUpdate implements ItemListener {

	private PnlGDBeheer pnlGDBeheer;
	private JTable lstg;
	private JTable lstd;
	private JComboBox<?> menubox;
	private JComboBox<?> conbox;
	private String selectedMenu;
	private String selectedCon;
	private TMRGerecht tmrg;
	private TMAGerecht tmag;
	private TMRDrank tmrd;
	private TMADrank tmad;
	private TMGerecht tmg;
	private TMDrank tmd;

	public ConCbUpdate(PnlGDBeheer pnlGDBeheer) {
		this.pnlGDBeheer = pnlGDBeheer;	
		tmrg = new TMRGerecht(pnlGDBeheer);
		tmag = new TMAGerecht(pnlGDBeheer);
		tmrd = new TMRDrank(pnlGDBeheer);
		tmad = new TMADrank(pnlGDBeheer);
		tmg  = new TMGerecht(pnlGDBeheer);
		tmd  = new TMDrank(pnlGDBeheer);
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		conbox = (JComboBox<?>) e.getSource();
		menubox = (JComboBox<?>)pnlGDBeheer.getBoxMenu();
		selectedCon = conbox.getSelectedItem().toString();
		selectedMenu = menubox.getSelectedItem().toString();
		System.out.println(selectedMenu);
		System.out.println(selectedCon);
		if (selectedMenu.equals("Afhaal")){
				if(selectedCon.equals("Gerecht")) {
					lstg = pnlGDBeheer.gettblCon();
					lstg.setModel(tmag);
					}
				if (selectedCon.equals("Drank")) {
					lstd = pnlGDBeheer.gettblCon();
					lstd.setModel(tmad);
					} }	
       else if (selectedMenu.equals("Restaurant")){
				if(selectedCon.equals("Gerecht")) {
					lstg = pnlGDBeheer.gettblCon();
					lstg.setModel(tmrg);
					}
				if (selectedCon.equals("Drank")) {
					lstd = pnlGDBeheer.gettblCon();
					lstd.setModel(tmrd);
					}}
       else if(selectedMenu.equals("Alles")){
			    if(selectedCon.equals("Gerecht")) {
				   lstg = pnlGDBeheer.gettblCon();
				   lstg.setModel(tmg);
				   }
			   if (selectedCon.equals("Drank")) {
				   lstd = pnlGDBeheer.gettblCon();
				   lstd.setModel(tmd);
				   }
			 }
	   }
}